<template>
  <el-row class="tac">
    <el-col :span="24">
      <el-menu
        :collapse="isCollapse"
        :uniqueOpened="true"
        class="el-menu-vertical-demo"
        :default-active="0"
      >
        <el-menu-item
          v-for="(item, index) in noChildren"
          :index="index"
          :key="index"
          @click="clickMenu(item)"
        >
          <i :class="'el-icon-' + item.icon"></i>
          <span slot="title">{{ item.label }}</span>
        </el-menu-item>

        <el-submenu index="index" v-for="item in hasChildren" :key="item.name">
          <template #title>
            <i :class="'el-icon-' + item.icon"></i>
            <span>{{ item.label }}</span>
          </template>
          <el-menu-item-group>
            <el-menu-item
              :index="subItem.path"
              v-for="(subItem, subIndex) in item.children"
              :key="subIndex"
              @click="clickMenu(subItem)"
            >
              {{ subItem.label }}
            </el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <!-- setting  -->
      </el-menu>
    </el-col>
  </el-row>
</template>

<script>
export default {
  computed: {
    noChildren() {
      return this.asideMenu.filter((item) => !item.children);
    },
    hasChildren() {
      return this.asideMenu.filter((item) => item.children);
    },
    isCollapse() {
      return this.$store.state.tab.isCollapse;
    },
  },
  data() {
    return {
      asideMenu: [
        {
          path: "/home",
          name: "home",
          label: "首页",
          icon: "s-home",
        },

        {
          path: "/study_school",
          name: "study_school",
          label: "在校学习",
          icon: "s-management",
        },
        {
          path: "/web",
          name: "web",
          label: "导航网站",
          icon: "s-promotion",
        },
        {
          path: "/study",
          name: "study",
          label: "学习",
          icon: "s-flag",
        },
        {
          path: "/ui",
          name: "ui",
          label: "UI框架",
          icon: "more",
        },
        {
          path: "/font",
          name: "font",
          label: "Font字体",
          icon: "place",
        },
        //二级菜单
      ],
    };
  },
  methods: {
    clickMenu(item) {
      this.$router.push({ name: item.name });
      this.$store.commit("selectMenu", item);
    },
  },
};
</script>

<style lang="scss" scoped>
.el-menu {
  height: 100%;
  border: none;
  i {
    color: black;
  }
}

//收缩动画
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
